package com.infocollect.project.api.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.infocollect.project.api.entity.TappPowerMenuEntity;
import com.infocollect.project.api.mapper.TappPowerMenuMapper;
import com.infocollect.project.api.service.ITappPowerMenuService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * (TappPowermenu)表服务实现类
 *
 * @author makejava
 * @since 2019-12-25 10:32:29
 */
@Service("tappPowermenuService")
public class TappPowerMenuServiceImpl extends ServiceImpl<TappPowerMenuMapper, TappPowerMenuEntity> implements ITappPowerMenuService {


    /**
     * 通过ID查询单条数据
     *
     * @param fid 主键
     * @return 实例对象
     */
    @Override
    public TappPowerMenuEntity queryById(Long fid) {
        return this.baseMapper.selectById(fid);
    }


    /**
     * 新增数据
     *
     * @param tappPowermenu 实例对象
     * @return 实例对象
     */
    @Override
    public TappPowerMenuEntity insert(TappPowerMenuEntity tappPowermenu) {
        this.baseMapper.insert(tappPowermenu);
        return tappPowermenu;
    }

    /**
     * 修改数据
     *
     * @param tappPowermenu 实例对象
     * @return 实例对象
     */
    @Override
    public TappPowerMenuEntity update(TappPowerMenuEntity tappPowermenu) {
        this.baseMapper.updateById(tappPowermenu);
        return this.queryById(tappPowermenu.getFid());
    }

    /**
     * 通过主键删除数据
     *
     * @param fid 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Long fid) {
        return this.baseMapper.deleteById(fid) > 0;
    }

    /**
     * 根据角色ID获取菜单权限
     *
     * @param roleid
     * @return
     */
    @Override
    public List<TappPowerMenuEntity> queryByRoleId(Long roleid) {
        QueryWrapper<TappPowerMenuEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("froleid", roleid);
        return baseMapper.selectList(queryWrapper);
    }

    /**
     * 通过角色id删除
     *
     * @param roleid 角色id
     * @return 影响行数
     */
    public boolean deleteByRoleId(Long roleid) {
        QueryWrapper<TappPowerMenuEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("froleid", roleid);
        return this.baseMapper.delete(queryWrapper) > 0;
    }
}